package com.design.pattern.compound;

public class DuckSimulator {
    public static void main(String[] args) {
        DuckSimulator duckSimulator = new DuckSimulator();
        AbstractDuckFactory duckFactory = new CountingDuckFactory();
        duckSimulator.simulator(duckFactory);
    }

    void simulator(AbstractDuckFactory duckFactory) {
        Quackable mallardDuck = duckFactory.createMallardDuck();
        Quackable rubberDuck = duckFactory.createRubberDuck();
        Quackable duckCall = duckFactory.createDuckCall();
        Quackable redheadDuck = duckFactory.createRedheadDuck();
        Quackable goose = new QuackCounter(new GooseAdapter(new Goose()));

        Flock duckFlock = new Flock();
        duckFlock.add(mallardDuck);
        duckFlock.add(rubberDuck);
        duckFlock.add(duckCall);
        duckFlock.add(redheadDuck);
        duckFlock.add(goose);

        Flock flockMallard = new Flock();
        Quackable mallardDuck1 = duckFactory.createMallardDuck();
        Quackable mallardDuck2 = duckFactory.createMallardDuck();
        Quackable mallardDuck3 = duckFactory.createMallardDuck();
        Quackable mallardDuck4 = duckFactory.createMallardDuck();

        flockMallard.add(mallardDuck1);
        flockMallard.add(mallardDuck2);
        flockMallard.add(mallardDuck3);
        flockMallard.add(mallardDuck4);

        Flock allFlock = new Flock();
        allFlock.add(duckFlock);
        allFlock.add(flockMallard);

        System.out.println("###duckFlock############");
        simulator(duckFlock);
        System.out.println("###flockMallard############");
        simulator(flockMallard);
        System.out.println("###allFlock############");
        simulator(allFlock);

        System.out.println("###quackologist############");
        Quackologist quackologist = new Quackologist();
        allFlock.registerObserver(quackologist);
        simulator(allFlock);

        System.out.println(QuackCounter.getNumberOfQuacks());
    }

    void simulator(Quackable duck) {
        duck.quack();
    }
}